<?php

class autocompleteJs extends JsPlugin {

    static private $instance;
    private $prePopulate = array();
    public static function getInstanceOf($plugin){
        $class_name = __CLASS__;
        if (!isset(self::$instance)) {
            self::$instance = new $class_name($plugin);
        }

        return self::$instance;
    }
    
    public function init(){
        $this->Html->LoadJs($this->url.'/jquery-autocomplete/lib/jquery.bgiframe.min');
        $this->Html->LoadJs($this->url.'/jquery-autocomplete/lib/jquery.ajaxQueue');
        $this->Html->LoadJs($this->url.'/jquery-autocomplete/lib/thickbox-compressed');
        $this->Html->LoadJs($this->url.'/jquery-autocomplete/jquery.autocomplete');
        $this->Html->loadExternCss($this->url.'/jquery-autocomplete/jquery.autocomplete');
        $this->Html->loadExternCss($this->url.'/jquery-autocomplete/lib/thickbox');
    }
    
    public function addToForm($form, $name, $array){
        $title = $array['name'];
        $model = $array['model'];
        $campo = implode("-",$array['keys']);
        $url = $this->url . "/completar.php?model=$model&campo=$campo";
        $this->Html->LoadJsFunction("
            $('#$name').autocomplete('$url',{
                delay: 300,
                minLength: 0,
                selectFirst: false,
                width:300
            });");
        $form->text($name, $title);
    }
    
    
}

?>